<template>
    <div>
        <div style="text-align:center!important">  
            <iframe :src="'data:application/pdf;base64,' + pdfBase64" frameborder="0" v-if="flag"></iframe>
        </div>
    </div>
</template>

<script setup name="viewItemFile">
import { getPdf,getXlsx } from '@/api/informationResult/evaluationReport/earthDamageLossPreEvaluation';
// pdf
import * as PDFJS from "pdfjs-dist/legacy/build/pdf";

import pdfjsWorker from "pdfjs-dist/legacy/build/pdf.worker.entry.js";
// 设置pdf.worker.js文件的引入地址
PDFJS.GlobalWorkerOptions.workerSrc = pdfjsWorker;

const { proxy } = getCurrentInstance();
const route = useRoute();
const pdfBase64 = ref('');
const flag = ref(false);

function getView() {
    proxy.$modal.loading();
    flag.value = false;
    getPdf({ id: route.query.id }).then(res => {
        flag.value = true;
        proxy.$modal.closeLoading();
        let blob = new Blob([res],{type: 'application/pdf;chartset=UTF-8'})
        let fileUrl = window.URL.createObjectURL(blob);
        var a = document.createElement("a");
        a.href = fileUrl;
        a.click();
    }).catch(err=>{
        flag.value = true;
        proxy.$modal.closeLoading();
    })

}
onMounted(()=>{
    getView();
})
</script>

<style scoped lang="scss">
.button {
    width: 100%;
    cursor: pointer;
}

.pdfView {
    width: 100%;
    // padding: 0px 100px 20px;
}

.btn {
    display: inline-block;
    padding: 5px;
    border-radius: 3px;
    border: 1px solid #333;
}

</style>